package com.example.demo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 计算预订天数
 */
public class GetDay {
    public int nDaysBetweenTwoDate(String arriveDate,String leaveDate) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date firstDate=null;
        Date secondDate=null;
        try {
            firstDate = df.parse(arriveDate);
            secondDate=df.parse(leaveDate);
        }
        catch(Exception e) {
            // 日期型字符串格式错误
        }

        int nDay=(int)((secondDate.getTime()-firstDate.getTime())/(24*60*60*1000));
        return nDay;
    }
}
